package com.ruoyi.common.config.mvc;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@Slf4j
public class TeamMvcConfig implements WebMvcConfigurer {

    // 图片的访问地址
    @Value("${portal.image-path}")
    private String imagePath;

    // 额外的图片存储路径
    private String additionalImagePath = "file:D:/IDEA_projects/RuoYi_Images/";

    /**
     * 配置静态资源处理器，将 /images/** 路径的请求映射到指定的图片存储路径
     * 配置资源的访问地址：http://localhost:8080/images/xxx.jpg
     * 将 /images/** 路径的请求映射到 imagePath 指定的物理路径
     *
     * @param registry 资源处理器注册器，用于添加资源处理规则
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        log.info("映射图片路径：{}", imagePath);
        registry.addResourceHandler("/images/**").addResourceLocations(imagePath, additionalImagePath);

    }

}
